package DanLiMoShi;

//饿汉式单例模式
public class Hungry {
    //私有化构造器
    private Hungry(){

    }
    //提前创建好私有对象
    private static Hungry hungry = new Hungry();
    //公有方法获取对象
    public static Hungry getInstance(){
        return hungry;
    }
}
class test{
    public static void main(String[] args) {
        Hungry hungry1 = Hungry.getInstance();
        Hungry hungry2 = Hungry.getInstance();
        System.out.println(hungry1==hungry2);
        System.out.println(hungry1.equals(hungry2));
        System.out.println(hungry1.hashCode()+"===="+hungry2.hashCode());
    }
}